import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        StudentManager studentManager = new StudentManager();

        while (true) {
            System.out.println("1. 添加学生信息");
            System.out.println("2. 根据ID查询学生信息");
            System.out.println("3. 显示所有学生信息");
            System.out.println("4. 计算学生各科目的平均分数");
            System.out.println("5. 退出");
            System.out.print("选择操作: ");
            int choice = scanner.nextInt();
            scanner.nextLine(); // Consume newline

            switch (choice) {
                case 1:
                    System.out.print("输入学生ID: ");
                    int id = scanner.nextInt();
                    scanner.nextLine(); // Consume newline
                    System.out.print("输入学生姓名: ");
                    String name = scanner.nextLine();
                    System.out.print("输入学生性别: ");
                    String gender = scanner.nextLine();
                    System.out.print("输入学生班级: ");
                    String className = scanner.nextLine();
                    System.out.print("输入学生高数成绩: ");
                    double mathScore = scanner.nextDouble();
                    scanner.nextLine(); // Consume newline
                    System.out.print("输入学生Java成绩: ");
                    double javaScore = scanner.nextDouble();
                    scanner.nextLine(); // Consume newline

                    Student student = new Student();
                    student.setId(id);
                    student.setName(name);
                    student.setGender(gender);
                    student.setClassName(className);
                    student.setMathScore(mathScore);
                    student.setJavaScore(javaScore);

                    studentManager.addStudent(student);
                    System.out.println("学生信息添加成功！");
                    break;

                case 2:
                    System.out.print("输入学生ID: ");
                    int queryId = scanner.nextInt();
                    Student queriedStudent = studentManager.getStudentById(queryId);
                    if (queriedStudent != null) {
                        System.out.println("学生信息: ID=" + queriedStudent.getId() + ", 姓名=" + queriedStudent.getName() +
                                ", 性别=" + queriedStudent.getGender() + ", 班级=" + queriedStudent.getClassName() +
                                ", 高数成绩=" + queriedStudent.getMathScore() + ", Java成绩=" + queriedStudent.getJavaScore());
                    } else {
                        System.out.println("未找到该ID的学生信息！");
                    }
                    break;

                case 3:
                    List<Student> students = studentManager.getAllStudents();
                    for (Student newstudent : students) {
                        System.out.println("学生信息: ID=" + newstudent.getId() + ", 姓名=" + newstudent.getName() +
                                ", 性别=" + newstudent.getGender() + ", 班级=" + newstudent.getClassName() +
                                ", 高数成绩=" + newstudent.getMathScore() + ", Java成绩=" + newstudent.getJavaScore());
                    }
                    break;

                case 4:
                    double[] averages = studentManager.calculateAverageScores();
                    System.out.println("高数平均成绩: " + averages[0]);
                    System.out.println("Java平均成绩: " + averages[1]);
                    break;

                case 5:
                    System.out.println("退出系统。");
                    scanner.close();
                    return;

                default:
                    System.out.println("无效选择，请重新输入！");
            }
        }
    }
}